package com.parttime.actions;

import java.io.IOException;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.json.annotations.JSON;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;
import com.parttime.beans.Personal_Users;
import com.parttime.service.PersonalUsersManager;

@ParentPackage("personal_users")
@Namespace("/")
@ExceptionMappings({@ExceptionMapping(exception = "java.lange.RuntimeException", result = "error")})
public class PersonalUsersAction extends CommonAction{
	@Autowired
	private PersonalUsersManager personal_UsersManager;
	
	private Personal_Users user;
	
	
	
	

	@Action(value="/register")
	public void Register() throws IOException{
		System.err.println("--------->");
		System.out.println(user);	
		try{
			if(personal_UsersManager.register(user))response.getWriter().print(1);
			
			
		}catch(Exception e){
			
			e.printStackTrace();
			response.getWriter().print(false);
			
			
		}
		
	}
	
	@Action(value="/validateEmail")
	public void validateEmail()throws Exception{
		String phone=request.getParameter("phone");
		String email=request.getParameter("email");
		String msg=personal_UsersManager.validateEmail(phone,email);
		response.setCharacterEncoding("utf-8");
		response.getWriter().print(msg);
	
		
	}
	
	@Action(value="/resetPassword")
	public void resetPassword() throws IOException{
		request.setCharacterEncoding("utf-8");
		String phone=request.getParameter("phone");
		String password=request.getParameter("password");
	    if(!personal_UsersManager.resetPassword(phone,password)){
	    	response.getWriter().print("保存密码错误");
	    }
	}




public Personal_Users getUser() {
	return user;
}

public void setUser(Personal_Users user) {
	this.user = user;
}









}
